//
//  LeiJiYiDuiXianFanDianViewController.m
//  FactorySale
//
//  Created by 李 on 2020/1/13.
//  Copyright © 2020 主事丫环. All rights reserved.
//
#import "LeiJiYiDuiXianFanDianViewController.h"
#import "LeiJiYiFanDianTopCell.h"
#import "LeiJiYiFanDianListCell.h"
#import "YiDuiXianFanDianListModel.h"


@interface LeiJiYiDuiXianFanDianViewController ()<UITableViewDelegate,UITableViewDataSource>
//列表
@property (nonatomic,strong) UITableView *listTableView;
@property (nonatomic,strong) NSMutableArray *listArray;
@property (nonatomic,strong) NSMutableArray *relsListArray;
@property (nonatomic,assign)NSInteger currentClickSection;

@end

static NSString *const LeiJiYiFanDianTopCellID = @"LeiJiYiFanDianTopCell";
static NSString *const LeiJiYiFanDianListCellID = @"LeiJiYiFanDianListCell";

@implementation LeiJiYiDuiXianFanDianViewController
- (void)viewWillAppear:(BOOL)animated {

    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];

}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"已兑现返点";
       [self.leftbutton setImage:imgname(@"left_icon") forState:(UIControlStateNormal)];
       self.view.backgroundColor = Main_BackGroundColor;
    [self addBackTableView];
    [self requestSalesVolume];

}
-(void)requestSalesVolume
{
    NSDictionary *param = @{
        
       };
    [NetWorkTool POST:hadSalesReturnList param:param success:^(id dic) {
        
        self.listArray = [YiDuiXianFanDianListModel mj_objectArrayWithKeyValuesArray:dic[@"data"]];
        [self.listTableView reloadData];



    } other:^(id dic) {
         ShowToastWithText(dic[@"msg"]);

    } fail:^(NSError *error) {

    } needUser:NO];
}
-(void)addBackTableView
{
    
    [self.listTableView registerNib:[UINib nibWithNibName:NSStringFromClass([LeiJiYiFanDianTopCell class]) bundle:nil] forCellReuseIdentifier:LeiJiYiFanDianTopCellID];
    [self.listTableView registerNib:[UINib nibWithNibName:NSStringFromClass([LeiJiYiFanDianListCell class]) bundle:nil] forCellReuseIdentifier:LeiJiYiFanDianListCellID];
     
     [self.view addSubview:self.listTableView];
    [self addHeaderView];
     
}
-(void)addHeaderView
{
      UIView *headerView = [[UIView alloc] init];
       headerView.backgroundColor = Main_BackGroundColor;
       headerView.frame = CGRectMake(10, 0, KWIDTH-20, 66+7);
    
      UIImageView *greenImage = [[UIImageView alloc] init];
      greenImage.frame = CGRectMake(10, 7, KWIDTH-20, 66);
      greenImage.image = imgname(@"圆角矩形 782 拷贝 5");
      [headerView addSubview:greenImage];
    
    UILabel *wordsLab = [[UILabel alloc]initWithFrame:CGRectMake(30, 30, 150, 14)];
       wordsLab.font = KFontPingFangSCMedium(14);
       wordsLab.textColor =[UIColor colorWithHexString:@"#FFFFFF"];
       wordsLab.text = @"累计已兑现返点";
       [headerView addSubview:wordsLab];
    
    UILabel *fanDianMoneyLab = [[UILabel alloc]initWithFrame:CGRectMake(KWIDTH-20-23-200, 30, 200, 14)];
          fanDianMoneyLab.font = KFontPingFangSCMedium(14);
          fanDianMoneyLab.textColor =[UIColor colorWithHexString:@"#FFFFFF"];
          fanDianMoneyLab.text =  [NSString stringWithFormat:@"%@",self.yiDuiXianMoney];
        fanDianMoneyLab.textAlignment = NSTextAlignmentRight;
          [headerView addSubview:fanDianMoneyLab];
    
    self.listTableView.tableHeaderView = headerView;
}
- (UITableView *)listTableView
{
    if (!_listTableView) {
        _listTableView = [[UITableView alloc] initWithFrame:CGRectMake(0,kNaviHeight, SCREEN_WIDTH, SCREEN_HEIGHT-kNaviHeight-TabbarSafeBottomMargin) style:UITableViewStylePlain];
        _listTableView.delegate = self;
        _listTableView.dataSource = self;
        _listTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
        _listTableView.estimatedSectionHeaderHeight = 0;
        _listTableView.estimatedSectionFooterHeight = 0;
        _listTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _listTableView.backgroundColor =  Main_BackGroundColor;
    }
    return _listTableView;
}
#pragma mark UITableView
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{

    return 10;

}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{

    return 0.01;

}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    
    UIView *headerView = [[UIView alloc] init];
    headerView.backgroundColor = Main_BackGroundColor;
    headerView.frame = CGRectMake(0, 0, KWIDTH, 10);
    return headerView;
    
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
       return nil;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (self.listArray.count>0) {
        return self.listArray.count+1;
    }
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row ==0) {
        return 48;
    }
    else {
        return 61;
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==0) {
        LeiJiYiFanDianTopCell *cell = [tableView dequeueReusableCellWithIdentifier:LeiJiYiFanDianTopCellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    if (indexPath.row>0) {
      
        YiDuiXianFanDianListModel *model = [self.listArray safeObjectAtIndex:indexPath.row-1];
        
        LeiJiYiFanDianListCell *cell = [tableView dequeueReusableCellWithIdentifier:LeiJiYiFanDianListCellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.model = model;
        
        return cell;
    }
     NSString *cellIdentifier = @"iden3";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
                   cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
               }

    return cell;

}

@end
